
package br.com.aeternu.controleatendimento.common.ui;

import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import br.com.aeternu.controleatendimento.common.ifc.IfcMensagemUsuario;

public class EasyOptionPane extends JOptionPane
{

   private static final long serialVersionUID = 1L;

   public EasyOptionPane()
   {
   }

   public EasyOptionPane(Object message)
   {
      super(message);
   }

   public EasyOptionPane(Object message, int messageType)
   {
      super(message, messageType);
   }

   public EasyOptionPane(Object message, int messageType, int optionType)
   {
      super(message, messageType, optionType);
   }

   public EasyOptionPane(Object message, int messageType, int optionType, Icon icon)
   {
      super(message, messageType, optionType, icon);
   }

   public EasyOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options)
   {
      super(message, messageType, optionType, icon, options);
   }

   public EasyOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue)
   {
      super(message, messageType, optionType, icon, options, initialValue);
   }

   public static void showErrorMessageDialog(Component parentComponent, Object message)
   {
      showMessageDialog(parentComponent, message, "", JOptionPane.ERROR_MESSAGE);
   }

   public static void showInfoMessageDialog(Component parentComponent, Object message)
   {
      showMessageDialog(parentComponent, message, "", JOptionPane.INFORMATION_MESSAGE);
   }

   public static void showInfoMessageDialog(Component parentComponent, Object message, String title)
   {
      showMessageDialog(parentComponent, message, title, JOptionPane.INFORMATION_MESSAGE);
   }

   public static void showMessageDialog(Component parentComponent, Object message)
   {
      showMessageDialog(parentComponent, message, "", INFORMATION_MESSAGE);
   }

   public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType)
   {
      showMessageDialog(parentComponent, message, title, messageType, null);
   }

   public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon)
   {
      showOptionDialog(parentComponent, message, getTitle(parentComponent, title), DEFAULT_OPTION, messageType, icon, null, null);
   }

   public static int showConfirmDialog(Component parentComponent, Object message)
   {
      return showConfirmDialog(parentComponent, message, "", YES_NO_CANCEL_OPTION);
   }

   public static int showConfirmDialog(Component parentComponent, Object message, int optionType)
   {
      return showConfirmDialog(parentComponent, message, "", optionType);
   }

   public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
   {
      return showConfirmDialog(parentComponent, message, title, optionType, QUESTION_MESSAGE);
   }

   public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType)
   {
      return showConfirmDialog(parentComponent, message, title, optionType, messageType, null);
   }

   public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon)
   {
      return showOptionDialog(parentComponent, message, getTitle(parentComponent, title), optionType, messageType, icon, null, null);
   }

   private static String getTitle(Object parentComponent, String title)
   {
      StringBuffer editedTitle = new StringBuffer(title);

      if (parentComponent != null)
         if (parentComponent instanceof JFrame)
         {
            editedTitle.append(((JFrame) parentComponent).getTitle());
         }
         else if (parentComponent instanceof JDialog)
         {
            editedTitle.append(((JDialog) parentComponent).getTitle());
         }

      if (!editedTitle.toString().contains(IfcMensagemUsuario.INFO_SOBRE))
         editedTitle.append((editedTitle.length() > 0 ? " - " : "") + (IfcMensagemUsuario.INFO_SOBRE));

      return editedTitle.toString();
   }
}
